package com.allianz.webapps.secondController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.allianz.webapps.common.CustomerContextHolder;
import com.allianz.webapps.https.interfaces.type001.pojo.User;
import com.allianz.webapps.service.AdT2PolicyAgentsService;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;


@Controller
@RequestMapping(value="/MyNotes")
public class MyNoteController {

	@Autowired
	private AdT2PolicyAgentsService   policyAgentsService;
	@Autowired
	private ObjectMapper obMapper;
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	
	@RequestMapping(value="/{pageName}")
	public ModelAndView pageSkip(@PathVariable("pageName") String pageName){
		logger.info(pageName);
		return new ModelAndView("views/page2/"+pageName);
	}
	
	 /**
	  * 获取全部菜单列表
	  * @param jsonParam
	  * @param session
	  * @return
	  */
	 @RequestMapping(value="/notSuccess")
	 public ModelAndView  getMenuList(HttpSession session){
		 //@RequestParam(value = "jsonParam") String jsonParam
		 return new ModelAndView("views/page/cover");
	 }
	 /**
	  * 
	  * @param jsonParam
	  * @return
	 * @throws IOException 
	 * @throws JsonMappingException 
	 * @throws JsonParseException 
	  */
	 @SuppressWarnings("unchecked")
	@RequestMapping(value="/getMyNoteList")
	 @ResponseBody
	 public List<Map<String,Object>> getMyNotes(@RequestParam(value="jsonParam")String jsonParam,HttpSession session) throws JsonParseException, JsonMappingException, IOException{
		 String policyRef ="";
		 String phName = "";
		 String cardType = "";
		 String cardCode = "";
		 User user = (User) session.getAttribute("username");
		 long agentId = Long.parseLong(user.getAgentId());
		 if (jsonParam != null) {
			 Map<String,Object> param=obMapper.readValue(jsonParam, Map.class);
			  policyRef = (String) param.get("policyRef");
			  phName = (String) param.get("phName");
			  cardType = (String) param.get("cardType");
			  cardCode = (String) param.get("cardCode");
		}
		 CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_ALLIANZ);
		 return policyAgentsService.getPolicyAgentsList(policyRef, phName, cardType, cardCode,agentId);
	 }
}
